//
//  SecondViewController.swift
//  Pickers
//
//  Created by 鲁万财 on 15/7/27.
//  Copyright (c) 2015年 鲁万财. All rights reserved.
//

import UIKit

class HHWSinglePicker: UIViewController,UIPickerViewDelegate,UIPickerViewDataSource {
    
    @IBOutlet weak var singlePicker: UIPickerView!;
    private var characterNames: Array<String> = [];

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        self.characterNames = ["Luke", "Leia", "Han", "Chewbacca", "Artoo", "Threepio", "Lando"];
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1;
    }
    
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return self.characterNames.count;
    }
    
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
        return self.characterNames[row];
    }
    
    @IBAction func buttonPressed(sender: AnyObject) {
        var row = self.singlePicker.selectedRowInComponent(0);
        var selected = self.characterNames[row];
        var title = String(format: "You selected %@", selected);
        var alert = UIAlertView(title: "Thank you for choosing.", message: title, delegate: nil, cancelButtonTitle: "You're Welcome");
        alert.show();
    }

}

